package com.app.core.util;

import android.annotation.SuppressLint;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

@SuppressLint("SimpleDateFormat")
/**
 * 时间工具类
 */
public class DateUtils {

    private static long minute = 1000 * 60;
    private static long hour = minute * 60;
    private static long day = hour * 24;
    private static long halfamonth = day * 15;
    private static long month = day * 30;



    /**
     * 获取当前时间
     * @return
     */
    public static String getCurremtTime() {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date curDate=new Date(System.currentTimeMillis());// 获取当前时间
        String str=format.format(curDate);
        return str;
    }


    /**
     * 获取年月
     * @return
     */
    public static String getYearMonth() {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
        Date curDate=new Date(System.currentTimeMillis());// 获取当前时间
        String str=format.format(curDate);
        return str;
    }







    /**
     * 转换小时分
     * @param time
     * @return
     */
    @SuppressWarnings("unused")
    public static String timeMinute(Long time) {
        SimpleDateFormat sdr = new SimpleDateFormat("HH:mm");
//        String times = sdr.format(new Date(time * 1000L));
        String times = sdr.format(new Date(time));
        return times;

    }


    public static String getCurremtMonth(Long time) {
        SimpleDateFormat format=new SimpleDateFormat("MM-dd HH:mm");
        String date =format.format(time);
        return date;
    }




    /**
     * 得到时间戳
     * @return
     */
    public static Long getTimeStamp() {
        return System.currentTimeMillis() / 1000;

    }


    /**
     * 将一个时间戳转换成提示性时间字符串，如刚刚，1秒前
     *
     * @param timeStamp
     * @return
     */
    public static String convertTimeToFormat(long timeStamp) {
        long curTime =System.currentTimeMillis() / (long) 1000 ;
        long time = curTime - timeStamp;

        if (time < 60 && time >= 0) {
            return "刚刚";
        } else if (time >= 60 && time < 3600) {
            return time / 60 + "分钟前";
        } else if (time >= 3600 && time < 3600 * 24) {
            return time / 3600 + "小时前";
        } else if (time >= 3600 * 24 && time < 3600 * 24 * 30) {
            return time / 3600 / 24 + "天前";
        } else if (time >= 3600 * 24 * 30 && time < 3600 * 24 * 30 * 12) {
            return time / 3600 / 24 / 30 + "个月前";
        } else if (time >= 3600 * 24 * 30 * 12) {
            return time / 3600 / 24 / 30 / 12 + "年前";
        } else {
            return "刚刚";
        }
    }


}
